import 'package:flutter/material.dart';
import '../services/ScreenAdapter.dart';

import '../widget/LoadingWidget.dart';
import 'ProductContent/ProductContentFirst.dart';

import 'ProductContent/ProductContentSecond.dart';

import 'ProductContent/ProductContentThird.dart';

import '../widget/JdButton.dart';

import '../config/Config.dart';

import 'package:dio/dio.dart';

import '../model/ProductContentModel.dart';

class ProductContentPage extends StatefulWidget {
  final Map arguments;
  const ProductContentPage({Key? key, required this.arguments})
      : super(key: key);

  @override
  State<ProductContentPage> createState() => _ProductContentPageState();
}

class _ProductContentPageState extends State<ProductContentPage> {
  List _productContentList=[];

  @override
  void initState() {
    super.initState();
    this._getContentData();
  }

  _getContentData() async{
    var api ='${Config.domain}api/pcontent?id=${widget.arguments['id']}';
    var result = await Dio().get(api);
    var productContent = new ProductContentModel.fromJson(result.data);
    setState(() {
      this._productContentList.add(productContent.result);
    });
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      child: Scaffold(
          appBar: AppBar(
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: ScreenAdapter.width(400),
                  child: TabBar(
                    indicatorColor: Colors.red,
                    // 表示下划线的宽度跟文字宽度一样
                    indicatorSize: TabBarIndicatorSize.label,
                    tabs: [
                      Tab(
                        child:
                            Text('商品', style: TextStyle(color: Colors.black87)),
                      ),
                      Tab(
                        child:
                            Text('详情', style: TextStyle(color: Colors.black87)),
                      ),
                      Tab(
                        child:
                            Text('评价', style: TextStyle(color: Colors.black87)),
                      ),
                    ],
                  ),
                )
              ],
            ),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.more_horiz),
                onPressed: () {
                  showMenu(
                      context: context,
                      position: RelativeRect.fromLTRB(
                          ScreenAdapter.width(600), 80, 0, 0),
                      items: [
                        PopupMenuItem(
                            child: Row(
                          children: <Widget>[Icon(Icons.home), Text('首页')],
                        )),
                        PopupMenuItem(
                            child: Row(
                          children: <Widget>[Icon(Icons.search), Text('搜索')],
                        )),
                      ]);
                },
              )
            ],
          ),
          body:this._productContentList.length>0?Stack(
            children: <Widget>[
              TabBarView(
                children: <Widget>[
                  ProductContentFirst(this._productContentList),
                  ProductContentSecond(this._productContentList),
                  ProductContentThird(),
                ],
              ),
              Positioned(
                  width: ScreenAdapter.width(750),
                  height: ScreenAdapter.height(90),
                  bottom: 0,
                  child: Container(
                    decoration: BoxDecoration(
                        border: Border(
                            top: BorderSide(color: Colors.black26, width: 1)),
                        color: Colors.white),
                    child: Row(
                      children: <Widget>[
                        Container(
                          padding:
                              EdgeInsets.only(top: ScreenAdapter.height(5)),
                          width: ScreenAdapter.width(120),
                          height: ScreenAdapter.height(90),
                          child: Column(
                            children: <Widget>[
                              Icon(Icons.shopping_cart),
                              Text('购物车')
                            ],
                          ),
                        ),
                        Expanded(
                            flex: 1,
                            child: JdButton(
                              color: Color.fromRGBO(253, 1, 0, 0.9),
                              text: '加入购物车',
                              callback: () {},
                            )),
                        Expanded(
                            flex: 1,
                            child: JdButton(
                              color: Color.fromRGBO(253, 165, 0, 0.9),
                              text: '立即购买',
                              callback: () {},
                            )),
                      ],
                    ),
                  ))
            ],
          ):LoadingWidget()),
      length: 3,
    );
  }
}
